home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QRZ! Ham Radio 8
/
QRZ Ham Radio Callsign Database - Volume 8.iso
/
pc
/
files
/
t_unix
/
bs941029.tgz
/
bbsx-941029.tar
/
bbsx
/
bbs_main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-10-29
|
4KB
|
183 lines
static char rcsid[] = "@(#) $Header: /home/dg1rtf/tcp/bbsx/RCS/bbs_main.c,v 1.2 1994/10/29 15:18:25 root Exp $";
#define _HPUX_SOURCE
#include <sys/types.h>
#include <stdio.h>
#include <ctype.h>
#include <pwd.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <termios.h>
#include <fcntl.h>
#include <time.h>
#include "bbs.hd"
#include "bbs.h"
/*---------------------------------------------------------------------------*/
int main (int argc, char **argv)
{
char *cp;
char *dir = WRKDIR;
char *sysname;
char buf[1024];
int c;
int err_flag = 0;
struct passwd *pw;
static struct termio save;
struct tm *tm;
long now;
char logfile[80];
struct log log;
now = time(0L);
tm=gmtime(&now);
sprintf(logfile,"%s%02d%02d.log",LOGFILE,tm->tm_year, tm->tm_mon);
ioctl(0,TCGETA,&save);
orig_escape = save.c_cc[VINTR];
escape_char = orig_escape;
signal(SIGINT, interrupt_handler);
signal(SIGQUIT, interrupt_handler);
signal(SIGALRM, alarm_handler);
umask(022);
sscanf(rcsid, "%*s %*s %*s %s %s %s %s %s",
revision.number,
revision.date,
revision.time,
revision.author,
revision.state);
if (chdir(dir)) {
mkdir(dir, 0755);
if (chdir(dir)) halt();
}
read_config();
#ifdef BOXBIN
init_crc();
#endif
bbs_adm = getpwnam(bbsadm);
is_bbs_adm = (bbs_adm->pw_uid == getuid());
pw = getpwnam(telluser);
is_tell_user = (pw->pw_uid == getuid());
while ((c = getopt(argc, argv, "df:mpw:")) != EOF)
switch (c) {
case 'd':
debug = 1;
break;
case 'f':
if (getuid() && !is_bbs_adm) {
puts("The 'f' option is for Store&Forward use only.");
exit(1);
}
sysname = optarg;
mode = BBS;
doforward = 1;
break;
case 'm':
mode = MAILorNEWS;
break;
case 'p':
packetcluster = 1;
break;
case 'w':
sleep(atoi(optarg));
break;
case '?':
err_flag = 1;
break;
}
if (optind < argc) err_flag = 1;
if (err_flag) {
puts("usage: bbs [-d] [-w seconds] [-f system|-m]");
exit(1);
}
if (!getcwd(buf, sizeof(buf))) halt();
user.cwd = strdup(buf);
if (gethostname(buf, sizeof(buf))) halt();
if (cp = strchr(buf, '.')) *cp = 0;
pw = doforward ? getpwnam(sysname) : getpwuid(getuid());
if (!pw) halt();
user.name = strdup(pw->pw_name);
if (!strcmp(user.name,"root") || (is_bbs_adm && !doforward)) {
strcpy(user.name,myhostname);
strlwc(user.name);
}
user.uid = pw->pw_uid;
user.gid = pw->pw_gid;
user.dir = strdup(pw->pw_dir);
user.shell = strdup(pw->pw_shell);
endpwent();
if (!user.uid || is_bbs_adm) level = ROOT;
if (is_bbs_adm && !doforward) level = ROOT;
if (connect_addr(user.name)) level = MBOX;
if (level != MBOX) init_aliasdb();
if (!getenv("LOGNAME")) {
sprintf(buf, "LOGNAME=%s", user.name);
putenv(strdup(buf));
}
if (!getenv("HOME")) {
sprintf(buf, "HOME=%s", user.dir);
putenv(strdup(buf));
}
if (!getenv("SHELL")) {
sprintf(buf, "SHELL=%s", user.shell);
putenv(strdup(buf));
}
if (!getenv("PATH"))
putenv("PATH=/bin:/usr/bin:/usr/contrib/bin:/usr/local/bin");
if (!getenv("TZ"))
putenv("TZ=MEZ-1MESZ");
if(!getenv("EDITOR")) {
putenv("EDITOR="EDITOR);
strcpy(editor,EDITOR);
}
else
strcpy(editor,getenv("EDITOR"));
if (level != MBOX)
get_seq();
if (level == MBOX)
binary_allowed = 0;
while (!(fdindex = open(INDEXFILE, O_RDWR | O_CREAT, 0644))) ;
if (fdindex < 0) halt();
if (log_reading && level == USER)
if ((fdlog = open(logfile, O_RDWR | O_CREAT, 0644)) <= 0) halt();
lowest_on_start = get_lowest_on_start();
highest_on_start = get_highest_on_start();
switch (mode) {
case BBS:
bbs();
break;
case MAILorNEWS:
recv_from_mail_or_news();
break;
}
return 0;
}